import mmap,time

# # 创建共享内存文件
# with open('shared_mem', 'w+b') as f:
#     f.truncate(1024)

# # 写入数据
# with open('shared_mem', 'r+b') as f:
#     mm = mmap.mmap(f.fileno(), length=1024)
#     mm[0:10] = b'HelloWorld'
#     mm.close()
# 读取数据
a=0
t1=time.time()
old_mm=""
Sleep_time=1/100_00000
with open('shared_mem', 'r+b') as f:
    mm = mmap.mmap(f.fileno(), length=1024)
    while 1:
        time.sleep(Sleep_time)
        if mm[0]==49:
            a+=1
            mm[0]=50
            if a%10000==0:
                int_v=int(mm[1:30].strip(b"\x00"))
                t2=time.time()
                print(t2-t1,int_v)
                t1=t2